*******************************************************************************
* All states
*******************************************************************************

use dataset_voters, clear

*** make ideology within-state ***

rename di_state state
egen sy_ideology_st = mean(sy_ideology), by(state)
gen sy_ideology_dm = sy_ideologymodel - sy_ideology_st
xtile qideo = sy_ideologymodel, nq(5)
xtile qideost = sy_ideology_dm, nq(5)
tabulate qideost, gen(qideost_)

forvalues i = 2(1)5 {
	gen d_`i' = anywells*qideost_`i'
}

*** do the regressions ***

xi: reg turnout qideost_2 qideost_3 qideost_4 qideost_5 ///
	anywells d_2 d_3 d_4 d_5 i.year, a(zipcode) cl(zipcode)

gen b = .
gen se = .

replace b = _b[anywells] if _n == 1
replace se = _se[anywells] if _n == 1

forvalues i = 2(1)5 {
	lincom anywells + d_`i'
	replace b = r(estimate) if _n == `i'
	replace se = r(se) if _n == `i'
}	

preserve

	drop if mi(b)
	gen index = _n
	collapse b se, by(index)
	gen ub = b + 1.96*se
	gen lb = b - 1.96*se
	
	#delimit;
	
	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,	
			legend(off)
			plotregion(style(none))
			ylab(, angle(horiz) format(%20.02fc))
			yline(0, lcol(gray))
			ytitle("Effect of fracking")
			xtitle("Liberalism quintile")
			title("All states")
			name(g1, replace)
			;
	
	#delimit cr
	
restore

*******************************************************************************
* High-fracking states
*******************************************************************************

use dataset_voters, clear
keep if highf==1

*** make ideology within-state ***

rename di_state state
egen sy_ideology_st = mean(sy_ideology), by(state)
gen sy_ideology_dm = sy_ideologymodel - sy_ideology_st
xtile qideo = sy_ideologymodel, nq(5)
xtile qideost = sy_ideology_dm, nq(5)
tabulate qideost, gen(qideost_)

forvalues i = 2(1)5 {
	gen d_`i' = anywells*qideost_`i'
}

*** do the regressions ***

xi: reg turnout qideost_2 qideost_3 qideost_4 qideost_5 ///
	anywells d_2 d_3 d_4 d_5 i.year, a(zipcode) cl(zipcode)

gen b = .
gen se = .

replace b = _b[anywells] if _n == 1
replace se = _se[anywells] if _n == 1

forvalues i = 2(1)5 {
	lincom anywells + d_`i'
	replace b = r(estimate) if _n == `i'
	replace se = r(se) if _n == `i'
}	

preserve

	drop if mi(b)
	gen index = _n
	collapse b se, by(index)
	gen ub = b + 1.96*se
	gen lb = b - 1.96*se
	
	#delimit;
	
	gr tw
		(sc b index, col(black))
		(rspike ub lb index, col(black))
		,	
			legend(off)
			plotregion(style(none))
			ylab(, angle(horiz) format(%20.02fc))
			yline(0, lcol(gray))
			ytitle("Effect of fracking")
			xtitle("Liberalism quintile")
			title("High-fracking states")
			name(g2, replace)
			;
	
	#delimit cr
	
restore

*******************************************************************************
* Combine plots
*******************************************************************************

gr combine g1 g2, rows(1) title("(A) Turnout") ysize(2) xsize(4) ycommon
gr export "_output/figure4a.pdf", replace

*******************************************************************************
* End
*******************************************************************************
